package com.yang.controller.wx;

import com.yang.bean.MarketCoupon;
import com.yang.bean.MarketUser;
import com.yang.bean.common.BasePageInfo;
import com.yang.bean.common.BaseRespVo;
import com.yang.bean.common.CommonData;
import com.yang.bean.szyWX.WxcouponExchangeBO;
import com.yang.bean.szyWX.WxcouponReceiveBO;
import com.yang.service.admin.AdminCouponService;
import com.yang.utils.UserUtil;
import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("wx/coupon")
public class WxCouponController {
    @Autowired
    AdminCouponService adminCouponService;
    @Autowired
    DefaultWebSessionManager defaultWebSessionManager;

    @RequestMapping("list")
    public BaseRespVo couponList(Integer page,Integer limit) {
        CommonData<MarketCoupon> data=adminCouponService.couponList(page,limit);
        return BaseRespVo.ok(data);

    }

    //待测试
    @RequestMapping("receive")
    public BaseRespVo receiveCoupon(@RequestBody WxcouponReceiveBO wxcouponReceiveBO, HttpServletRequest request) {
        adminCouponService.receiveCoupon(wxcouponReceiveBO,request);
            return BaseRespVo.error("你猜猜领没领");
    }

    @RequestMapping("mylist")
    public BaseRespVo queryAllMyCoupon(BasePageInfo info, Integer status, HttpServletRequest request) {
        MarketUser user = UserUtil.getUserMsg(request, defaultWebSessionManager);
        CommonData data = adminCouponService.queryAllMyCoupon(info, status, user.getId());
        return BaseRespVo.ok(data);
    }

    @RequestMapping("exchange")
    public BaseRespVo exchangeCoupon(@RequestBody WxcouponExchangeBO wxcouponExchangeBO,HttpServletRequest request){
        adminCouponService.exchangeCoupon(wxcouponExchangeBO,request);
        return BaseRespVo.ok();
    }

    @RequestMapping("selectlist")
    public BaseRespVo selectListCoupon(Integer cartId, Integer grouponRulesId, HttpServletRequest request) {
        MarketUser user = UserUtil.getUserMsg(request, defaultWebSessionManager);
        CommonData data=adminCouponService.selectListCoupon(cartId,grouponRulesId, user.getId());
        return BaseRespVo.ok(data);
    }

}
